package com.zhaojun.cloud.service.order.shiro;


import com.zhaojun.cloud.support.shiro.ShiroBaseConfiguration;
import com.zhaojun.cloud.support.shiro.ShiroServerUrlUtil;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

import java.util.HashMap;
import java.util.Map;

/**
 * wwj
 * 2018/12/18  16:34
 */
@Configuration
@DependsOn("shiroServerUrlUtil")
public class ShiroClientConfiguration extends ShiroBaseConfiguration {


    //Filter工厂，设置对应的过滤条件和跳转条件
    @Bean
    public ShiroFilterFactoryBean shiroFilterFactoryBean(SecurityManager securityManager) {
        ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
        shiroFilterFactoryBean.setSecurityManager(securityManager);
        Map<String, String> map = new HashMap<String, String>();
        //登出
        //对所有用户认证
        map.put("/**", "authc");
        //登录
        shiroFilterFactoryBean.setLoginUrl(ShiroServerUrlUtil.notLogin_url);
        shiroFilterFactoryBean.setUnauthorizedUrl(ShiroServerUrlUtil.notRole_url);
        //首页
//        shiroFilterFactoryBean.setSuccessUrl("/index");
        //错误页面，认证不通过跳转
        shiroFilterFactoryBean.setFilterChainDefinitionMap(map);
        return shiroFilterFactoryBean;
    }
}
